CREATE TRIGGER trigger_HulladekLerako
 ON HulladekLerako
     
   instead of Delete
    AS  declare @v Int
     BEGIN  
    	Delete From HulladeklerakoTulajdonos 
    	where  ( select HulladekLerakoId  from deleted) =  HulladekLerakoId
    
		Delete From HulladeklerakoEllenorzese
		where ( select HulladekLerakoId  from deleted) =  HulladekLerakoId
		
		declare t2 cursor for
			select atrakoallomasID from Atrakoallomas
			where ( select HulladekLerakoId  from deleted) =  HulladekLerakoId
			
		open t2
		fetch next from t2 into @v
		while @@fetch_status = 0
		begin
				Delete From AtrakoAllomas 
			where AtrakoAllomasID = @v
		
		fetch next from t2 into @v
			  end
			close t2
		deallocate t2		
		
		Delete From Hulladeklerako
		where ( select HulladekLerakoId  from deleted) =  HulladekLerakoId
		
end